package com.ship.dispatch.service.shipBusiness.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ship.common.core.exception.BusException;
import com.ship.common.core.exception.ServiceException;
import com.ship.common.core.utils.StringUtil;
import com.ship.common.core.web.domain.BaseResultCode;
import com.ship.common.core.web.domain.JsonResult;
import com.ship.common.business.service.impl.BaseServiceImpl;
import com.ship.dispatch.bean.SpInformation;
import com.ship.dispatch.bean.TzFuelRecord;
import com.ship.dispatch.bean.boats.info.QueryEvaporationConsumptionTrendInfo;
import com.ship.dispatch.bean.boats.info.QueryFuelConsumptionTrendInfo;
import com.ship.dispatch.bean.boats.info.QueryReportInfo;
import com.ship.dispatch.bean.fob.SpFobFileRecord;
import com.ship.dispatch.bean.orderPay.SpPaymentOrder;
import com.ship.dispatch.bean.shipBusiness.SmShipReport;
import com.ship.dispatch.bean.shipBusiness.SmShipReportRecord;
import com.ship.dispatch.bpm.service.ProcessInstanceService;
import com.ship.dispatch.mapper.shipBusiness.SmShipReportMapper;
import com.ship.dispatch.model.dto.shipReport.ShipReportDto;
import com.ship.dispatch.service.SpInformationService;
import com.ship.dispatch.service.TzFuelRecordService;
import com.ship.dispatch.service.fob.SpFobFileRecordService;
import com.ship.dispatch.service.shipBusiness.SmShipReportRecordService;
import com.ship.dispatch.service.shipBusiness.SmShipReportService;
import com.ship.dispatch.util.IDUtil;
import com.ship.common.security.utils.SecurityUtils;
import com.ship.dispatch.vo.shipReport.OptionsVO;
import com.ship.dispatch.vo.shipReport.ShipReportDetailDataVO;
import com.ship.dispatch.vo.shipReport.ShipReportDetailVO;
import com.ship.system.api.BpmInstanceService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hpsf.Decimal;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service
public class SmShipReportServiceImpl extends BaseServiceImpl<SmShipReportMapper, SmShipReport> implements SmShipReportService {

    @Autowired
    private SmShipReportRecordService shipReportRecordService;
    @Autowired
    private SpInformationService informationService;
    @Autowired
    @Lazy
    private TzFuelRecordService tzFuelRecordService;

    /**
     * 修改船舶午报
     *
     * @return
     */
    @Override
    public SmShipReport updateShipReport(ShipReportDto shipReportDto,SpFobFileRecordService spFobFileRecordService) {
        SmShipReport shipReport = this.getById(shipReportDto.getId());
        BeanUtils.copyProperties(shipReportDto, shipReport);
        shipReport.setUpdateDate(new Date());
        this.updateById(shipReport);

        //新增船舶午报动态
        SpFobFileRecord fileRecord = spFobFileRecordService.getById(shipReport.getFileRecordId());
        SmShipReportRecord shipReportRecord = new SmShipReportRecord();
        shipReportRecord.setShipReportId(shipReport.getFileRecordId());
        shipReportRecord.setOperateType(2);
        shipReportRecord.setOperateRemark("编辑船舶午报:" + fileRecord.getName());
        shipReportRecord.setOperateTime(new Date());
        shipReportRecord.setOperateBy(SecurityUtils.getUsername());
        shipReportRecordService.save(shipReportRecord);

        TzFuelRecord fuelRecord = new TzFuelRecord();
        fuelRecord.setShipName(shipReport.getVesselName());
        fuelRecord.setImo(shipReport.getImo());
        if(null != shipReport.getShipReportDate()){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            fuelRecord.setMessageDate(sdf.format(shipReport.getShipReportDate()));
        }
        //VLSFO 日剩余量
        BigDecimal remainingLsfo = BigDecimal.ZERO;
        if(null != shipReport.getRemainingLsfo()){
            remainingLsfo = new BigDecimal(shipReport.getRemainingLsfo());
        }
        fuelRecord.setVlsfoDayLeave(remainingLsfo);
        //VLSFO 日消耗量
        BigDecimal consumptionLsfo = BigDecimal.ZERO;
        if(null != shipReport.getConsumptionLsfo()){
            consumptionLsfo = new BigDecimal(shipReport.getConsumptionLsfo());
        }
        fuelRecord.setVlsfoDayUse(consumptionLsfo);
        //LSMGO日 剩余量
        BigDecimal remainingLsmdo = BigDecimal.ZERO;
        if(null != shipReport.getRemainingLsgo()){
            remainingLsmdo = shipReport.getRemainingLsgo();
        }
        fuelRecord.setLsmgoDayLeave(remainingLsmdo);
        //LSMGO日消耗量
        BigDecimal consumptionLsmdo = BigDecimal.ZERO;
        if(null != shipReport.getConsumptionLsgo()){
            consumptionLsmdo = shipReport.getConsumptionLsgo();
        }
        fuelRecord.setLsmgoDayUse(consumptionLsmdo);
        fuelRecord.setOperaType(2);
        tzFuelRecordService.dataTransfer(fuelRecord);

        return shipReport;
    }

    /**
     * 通过午报id获取详情
     *
     * @param id
     * @return
     */
    @Override
    public List<ShipReportDetailVO> getShipReportDetail(Long id) {
        List<ShipReportDetailVO> shipReportDetailVOS = new ArrayList<>();
        SmShipReport shipReport = this.baseMapper.selectById(id);
        if (null != shipReport) {
            //基础信息：Vessel Info
            ShipReportDetailVO vesselInfo = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> vesselInfoData = new ArrayList<>();
            vesselInfo.setTitle("Vessel Info(基础信息)");
            vesselInfo.setId("VesselInfo");
            vesselInfo.setFormatType(1);
            ShipReportDetailDataVO vesselName = new ShipReportDetailDataVO();
            vesselName.setKey("vesselName");
            vesselName.setValue(shipReport.getVesselName());
            vesselName.setType("input");
            vesselName.setDescribe("vessel name");
            vesselInfoData.add(vesselName);
            ShipReportDetailDataVO imo = new ShipReportDetailDataVO();
            imo.setKey("imo");
            imo.setValue(shipReport.getImo());
            imo.setType("input");
            imo.setDescribe("IMO");
            vesselInfoData.add(imo);
            ShipReportDetailDataVO callsign = new ShipReportDetailDataVO();
            callsign.setKey("callsign");
            callsign.setValue(shipReport.getCallsign());
            callsign.setType("input");
            callsign.setDescribe("Callsign");
            vesselInfoData.add(callsign);
            ShipReportDetailDataVO flag = new ShipReportDetailDataVO();
            flag.setKey("flag");
            flag.setValue(shipReport.getFlag());
            flag.setType("input");
            flag.setDescribe("Flag");
            vesselInfoData.add(flag);
            ShipReportDetailDataVO voyageNumber = new ShipReportDetailDataVO();
            voyageNumber.setKey("voyageNumber");
            voyageNumber.setValue(shipReport.getVoyageNumber());
            voyageNumber.setType("input");
            voyageNumber.setDescribe("Voyage number");
            vesselInfoData.add(voyageNumber);
            vesselInfo.setData(vesselInfoData);

            //时间：Time
            ShipReportDetailVO time = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> timeData = new ArrayList<>();
            time.setTitle("Time(时间)");
            time.setId("Time");
            time.setFormatType(1);
            ShipReportDetailDataVO date = new ShipReportDetailDataVO();
            date.setKey("shipReportDate");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
            if (null != shipReport.getShipReportDate()) {
                date.setValue(sdf.format(shipReport.getShipReportDate()));
            }
            date.setType("date");
            date.setFormat("YYYY/MM/DD");
            date.setDescribe("Date");
            timeData.add(date);
            ShipReportDetailDataVO lt = new ShipReportDetailDataVO();
            lt.setKey("shipReportLt");
            lt.setValue(shipReport.getShipReportLt());
            lt.setType("input");
            lt.setDescribe("LT");
            timeData.add(lt);
            ShipReportDetailDataVO utc = new ShipReportDetailDataVO();
            utc.setKey("shipReportUtc");
            utc.setValue(shipReport.getShipReportUtc());
            utc.setType("input");
            utc.setDescribe("UTC");
            timeData.add(utc);
            ShipReportDetailDataVO etaNextPort = new ShipReportDetailDataVO();
            etaNextPort.setKey("etaNextPort");
            etaNextPort.setValue(shipReport.getEtaNextPort());
            etaNextPort.setType("input");
            etaNextPort.setDescribe("ETA NEXT PORT");
            timeData.add(etaNextPort);
            time.setData(timeData);

            //位置：Position
            ShipReportDetailVO position = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> positionData = new ArrayList<>();
            position.setTitle("Position(位置)");
            position.setId("Position");
            position.setFormatType(1);
            ShipReportDetailDataVO lat = new ShipReportDetailDataVO();
            lat.setKey("positionLat");
            lat.setValue(shipReport.getPositionLat());
            lat.setType("input");
            lat.setDescribe("LAT");
            positionData.add(lat);
            ShipReportDetailDataVO longPostion = new ShipReportDetailDataVO();
            longPostion.setKey("positionLong");
            longPostion.setValue(shipReport.getPositionLong());
            longPostion.setType("input");
            longPostion.setDescribe("LONG");
            positionData.add(longPostion);
            ShipReportDetailDataVO deviation = new ShipReportDetailDataVO();
            deviation.setKey("deviations");
            deviation.setValue(shipReport.getDeviations());
            deviation.setType("input");
            deviation.setDescribe("Deviations");
            positionData.add(deviation);
            position.setData(positionData);

            //距离和速度：Distance&Speed
            ShipReportDetailVO distanceSpeed = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> distanceSpeedData = new ArrayList<>();
            distanceSpeed.setTitle("Distance&Speed(距离和速度)");
            distanceSpeed.setId("Distance&Speed");
            distanceSpeed.setFormatType(1);
            ShipReportDetailDataVO observed = new ShipReportDetailDataVO();
            observed.setKey("lastReportMiles");
            if (null != shipReport.getLastReportMiles()) {
                observed.setValue(shipReport.getLastReportMiles().toString());
            }
            observed.setType("input");
            observed.setDescribe("Observed distance since last report");
            observed.setUnit("N.miles");
            distanceSpeedData.add(observed);
            ShipReportDetailDataVO steamTime = new ShipReportDetailDataVO();
            steamTime.setKey("steamingTime");
            steamTime.setValue(shipReport.getSteamingTime());
            steamTime.setType("input");
            steamTime.setDescribe("Steaming Time since last report");
            distanceSpeedData.add(steamTime);
            ShipReportDetailDataVO totalDistance = new ShipReportDetailDataVO();
            totalDistance.setKey("faopMiles");
            if (null != shipReport.getFaopMiles()) {
                totalDistance.setValue(shipReport.getFaopMiles().toString());
            }
            totalDistance.setType("input");
            totalDistance.setDescribe("Total distance since FAOP");
            totalDistance.setUnit("N.miles");
            distanceSpeedData.add(totalDistance);
            ShipReportDetailDataVO distanceNextPort = new ShipReportDetailDataVO();
            distanceNextPort.setKey("nextPortMiles");
            distanceNextPort.setValue(shipReport.getNextPortMiles());
            distanceNextPort.setType("input");
            distanceNextPort.setDescribe("Distance to go - To Next Port");
            distanceNextPort.setUnit("N.miles");
            distanceSpeedData.add(distanceNextPort);
            ShipReportDetailDataVO distanceFinal = new ShipReportDetailDataVO();
            distanceFinal.setKey("finalDestinationMiles");
            distanceFinal.setValue(shipReport.getFinalDestinationMiles());
            distanceFinal.setType("input");
            distanceFinal.setDescribe("Distance to go - To Final destination");
            distanceFinal.setUnit("N.miles");
            distanceSpeedData.add(distanceFinal);
            ShipReportDetailDataVO averageSpeed = new ShipReportDetailDataVO();
            averageSpeed.setKey("lastReportKnots");
            if (null != shipReport.getLastReportKnots()) {
                averageSpeed.setValue(shipReport.getLastReportKnots().toString());
            }
            averageSpeed.setType("input");
            averageSpeed.setDescribe("Average speed since last report");
            averageSpeed.setUnit("Knots");
            distanceSpeedData.add(averageSpeed);
            ShipReportDetailDataVO speedScheduled = new ShipReportDetailDataVO();
            speedScheduled.setKey("scheduledEtaKnots");
            speedScheduled.setValue(shipReport.getScheduledEtaKnots());
            speedScheduled.setType("input");
            speedScheduled.setDescribe("Speed required to make scheduled ETA");
            speedScheduled.setUnit("Knots");
            distanceSpeedData.add(speedScheduled);
            distanceSpeed.setData(distanceSpeedData);

            //消耗油/LNG：Consumption since last report
            ShipReportDetailVO consumptionLng = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> consumptionLngData = new ArrayList<>();
            consumptionLng.setTitle("Consumption since last report(消耗油/LNG)");
            consumptionLng.setId("Consumption since last report");
            consumptionLng.setFormatType(1);
            ShipReportDetailDataVO consumptionLngFO = new ShipReportDetailDataVO();
            consumptionLngFO.setKey("consumptionFo");
            if (null != shipReport.getConsumptionFo()) {
                consumptionLngFO.setValue(shipReport.getConsumptionFo().toString());
            }
            consumptionLngFO.setType("input");
            consumptionLngFO.setDescribe("F.O.");
            consumptionLngFO.setUnit("tonnes");
            consumptionLngData.add(consumptionLngFO);
            ShipReportDetailDataVO consumptionLsfo = new ShipReportDetailDataVO();
            consumptionLsfo.setKey("consumptionLsfo");
            if (null != shipReport.getConsumptionLsfo()) {
                consumptionLsfo.setValue(shipReport.getConsumptionLsfo().toString());
            }
            consumptionLsfo.setType("input");
            consumptionLsfo.setDescribe("L. S. F. O.");
            consumptionLsfo.setUnit("tonnes");
            consumptionLngData.add(consumptionLsfo);
            ShipReportDetailDataVO consumptionLsmdo = new ShipReportDetailDataVO();
            consumptionLsmdo.setKey("consumptionLsmdo");
            if (null != shipReport.getConsumptionLsmdo()) {
                consumptionLsmdo.setValue(shipReport.getConsumptionLsmdo().toString());
            }
            consumptionLsmdo.setType("input");
            consumptionLsmdo.setDescribe("L.S.M.D.O.");
            consumptionLsmdo.setUnit("tonnes");
            consumptionLngData.add(consumptionLsmdo);
            ShipReportDetailDataVO consumptionGo = new ShipReportDetailDataVO();
            consumptionGo.setKey("consumptionGo");
            if (null != shipReport.getConsumptionGo()) {
                consumptionGo.setValue(shipReport.getConsumptionGo().toString());
            }
            consumptionGo.setType("input");
            consumptionGo.setDescribe("G.O.");
            consumptionGo.setUnit("tonnes");
            consumptionLngData.add(consumptionGo);
            ShipReportDetailDataVO consumptionLsgo = new ShipReportDetailDataVO();
            consumptionLsgo.setKey("consumptionLsgo");
            if (null != shipReport.getConsumptionLsgo()) {
                consumptionLsgo.setValue(shipReport.getConsumptionLsgo().toString());
            }
            consumptionLsgo.setType("input");
            consumptionLsgo.setDescribe("L.S.G.O.");
            consumptionLsgo.setUnit("tonnes");
            consumptionLngData.add(consumptionLsgo);
            ShipReportDetailDataVO consumptionLngs = new ShipReportDetailDataVO();
            consumptionLngs.setKey("LNG");
            if (null != shipReport.getLngMg() && null != shipReport.getLngDg()) {
                consumptionLngs.setValue("lngMg/" + shipReport.getLngMg().toString() + "/m³,lngDg/" + shipReport.getLngDg().toString() + "/m³,lngGcu/" + shipReport.getLngGcu().toString() + "/m³");
            }
            consumptionLngs.setType("select");
            consumptionLngs.setDescribe("LNG");
            List<OptionsVO> optionsVOS = new ArrayList<>();
            OptionsVO lngMgOptionsVO = new OptionsVO();
            lngMgOptionsVO.setKey("lngMg");
            if(null != shipReport.getLngMg()){
                lngMgOptionsVO.setValue(shipReport.getLngMg().toString());
            }
            lngMgOptionsVO.setUnit("m³");
            OptionsVO lngDgOptionsVO = new OptionsVO();
            lngDgOptionsVO.setKey("lngDg");
            if(null != shipReport.getLngDg()){
                lngDgOptionsVO.setValue(shipReport.getLngDg().toString());
            }
            lngDgOptionsVO.setUnit("m³");
            OptionsVO lngGcuOptionsVO = new OptionsVO();
            lngGcuOptionsVO.setKey("lngGcu");
            if(null != shipReport.getLngGcu()){
                lngGcuOptionsVO.setValue(shipReport.getLngGcu().toString());
            }
            lngGcuOptionsVO.setUnit("m³");
            optionsVOS.add(lngGcuOptionsVO);
            optionsVOS.add(lngDgOptionsVO);
            optionsVOS.add(lngMgOptionsVO);
            consumptionLngs.setOptions(optionsVOS);

            consumptionLngs.setUnit("");
            consumptionLngData.add(consumptionLngs);
            ShipReportDetailDataVO consumptionLngFor = new ShipReportDetailDataVO();
            consumptionLngFor.setKey("lngConsumptionFor");
            consumptionLngFor.setValue(shipReport.getLngConsumptionFor() != null ? shipReport.getLngConsumptionFor():"");
            consumptionLngFor.setType("input");
            consumptionLngFor.setDescribe("LNG consumption for");
            consumptionLngData.add(consumptionLngFor);
            consumptionLng.setData(consumptionLngData);

            //船上还剩的油/LNG：Remaining on board
            ShipReportDetailVO remainBoard = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> remainBoardData = new ArrayList<>();
            remainBoard.setTitle("Remaining on board(船上还剩的油/LNG)");
            remainBoard.setId("Remaining on board");
            remainBoard.setFormatType(1);
            ShipReportDetailDataVO remainingFO = new ShipReportDetailDataVO();
            remainingFO.setKey("remainingFo");
            if (null != shipReport.getRemainingFo()) {
                remainingFO.setValue(shipReport.getRemainingFo().toString());
            }
            remainingFO.setType("input");
            remainingFO.setDescribe("F.O.");
            remainingFO.setUnit("tonnes");
            remainBoardData.add(remainingFO);
            ShipReportDetailDataVO remainingLsfo = new ShipReportDetailDataVO();
            remainingLsfo.setKey("remainingLsfo");
            if (null != shipReport.getRemainingLsfo()) {
                remainingLsfo.setValue(shipReport.getRemainingLsfo().toString());
            }
            remainingLsfo.setType("input");
            remainingLsfo.setDescribe("L. S. F. O.");
            remainingLsfo.setUnit("tonnes");
            remainBoardData.add(remainingLsfo);
            ShipReportDetailDataVO remainingLsmdo = new ShipReportDetailDataVO();
            remainingLsmdo.setKey("remainingLsmdo");
            if (null != shipReport.getRemainingLsmdo()) {
                remainingLsmdo.setValue(shipReport.getRemainingLsmdo().toString());
            }
            remainingLsmdo.setType("input");
            remainingLsmdo.setDescribe("L.S.M.D.O.");
            remainingLsmdo.setUnit("tonnes");
            remainBoardData.add(remainingLsmdo);
            ShipReportDetailDataVO remainingGo = new ShipReportDetailDataVO();
            remainingGo.setKey("remainingGo");
            if (null != shipReport.getRemainingGo()) {
                remainingGo.setValue(shipReport.getRemainingGo().toString());
            }
            remainingGo.setType("input");
            remainingGo.setDescribe("G.O.");
            remainingGo.setUnit("tonnes");
            remainBoardData.add(remainingGo);
            ShipReportDetailDataVO remainingLsgo = new ShipReportDetailDataVO();
            remainingLsgo.setKey("remainingLsgo");
            if (null != shipReport.getRemainingLsgo()) {
                remainingLsgo.setValue(shipReport.getRemainingLsgo().toString());
            }
            remainingLsgo.setType("input");
            remainingLsgo.setDescribe("L.S.G.O.");
            remainingLsgo.setUnit("tonnes");
            remainBoardData.add(remainingLsgo);
            ShipReportDetailDataVO remainingLng = new ShipReportDetailDataVO();
            remainingLng.setKey("remainingLng");
            if (null != shipReport.getRemainingLng()) {
                remainingLng.setValue(shipReport.getRemainingLng().toString());
            }
            remainingLng.setType("input");
            remainingLng.setDescribe("LNG");
            remainingLng.setUnit("m³");
            remainBoardData.add(remainingLng);
            remainBoard.setData(remainBoardData);

            //Total F.O. consumption since FAOP（tonnes）
            ShipReportDetailVO totalConsumpFaop = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> totalConsumpFaopData = new ArrayList<>();
            totalConsumpFaop.setTitle("");
            totalConsumpFaop.setId("Total F.O. consumption since FAOP");
            totalConsumpFaop.setFormatType(2);
            ShipReportDetailDataVO totalConsumpFaopDetail = new ShipReportDetailDataVO();
            totalConsumpFaopDetail.setKey("totalFoFaop");
            if (null != shipReport.getTotalFoFaop()) {
                totalConsumpFaopDetail.setValue(shipReport.getTotalFoFaop().toString());
            }
            totalConsumpFaopDetail.setType("input");
            totalConsumpFaopDetail.setDescribe("Total F.O. consumption since FAOP");
            totalConsumpFaopDetail.setUnit("tonnes");
            totalConsumpFaopData.add(totalConsumpFaopDetail);
            totalConsumpFaop.setData(totalConsumpFaopData);

            //发动机：Engine
            ShipReportDetailVO engine = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> engineData = new ArrayList<>();
            engine.setTitle("Engine(发动机)");
            engine.setId("Engine");
            engine.setFormatType(1);
            ShipReportDetailDataVO engineDetail = new ShipReportDetailDataVO();
            engineDetail.setKey("engineRpm");
            if (null != shipReport.getEngineRpm()) {
                engineDetail.setValue(shipReport.getEngineRpm().toString());
            }
            engineDetail.setType("input");
            engineDetail.setDescribe("Engine RPM since last noon report");
            engineDetail.setUnit("RPM");
            engineData.add(engineDetail);
            ShipReportDetailDataVO enginePower = new ShipReportDetailDataVO();
            enginePower.setKey("enginePowerKw");
            if (null != shipReport.getEnginePowerKw()) {
                enginePower.setValue(shipReport.getEnginePowerKw().toString());
            }
            enginePower.setType("input");
            enginePower.setDescribe("Engine power");
            enginePower.setUnit("KW");
            engineData.add(enginePower);
            ShipReportDetailDataVO engineTorque = new ShipReportDetailDataVO();
            engineTorque.setKey("engineTorqueKn");
            if (null != shipReport.getEngineTorqueKn()) {
                engineTorque.setValue(shipReport.getEngineTorqueKn().toString());
            }
            engineTorque.setType("input");
            engineTorque.setDescribe("Engine torque");
            engineTorque.setUnit("KN-m");
            engineData.add(engineTorque);
            ShipReportDetailDataVO pctSlip = new ShipReportDetailDataVO();
            pctSlip.setKey("pctSlip");
            if (null != shipReport.getPctSlip()) {
                pctSlip.setValue(shipReport.getPctSlip().toString());
            }
            pctSlip.setType("input");
            pctSlip.setDescribe("Pct. Slip");
            pctSlip.setUnit("%");
            engineData.add(pctSlip);
            engine.setData(engineData);

            //油气转换：Fuel/LNG
            ShipReportDetailVO fuel = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> fuelData = new ArrayList<>();
            fuel.setTitle("Fuel/LNG(油气转换)");
            fuel.setId("Fuel/LNG");
            fuel.setFormatType(1);
            ShipReportDetailDataVO fuelOil = new ShipReportDetailDataVO();
            fuelOil.setKey("fuelOilFactor");
            if (null != shipReport.getFuelOilFactor()) {
                fuelOil.setValue(shipReport.getFuelOilFactor().toString());
            }
            fuelOil.setType("input");
            fuelOil.setDescribe("Fuel oil equivalent factor");
            fuelData.add(fuelOil);
            ShipReportDetailDataVO fuelEquival = new ShipReportDetailDataVO();
            fuelEquival.setKey("lngFuelEquivalent");
            if (null != shipReport.getLngFuelEquivalent()) {
                fuelEquival.setValue(shipReport.getLngFuelEquivalent().toString());
            }
            fuelEquival.setType("input");
            pctSlip.setUnit("tonnes");
            fuelEquival.setDescribe("LNG fuel equivalent");
            fuelData.add(fuelEquival);
            fuel.setData(fuelData);

            //天气：Weather
            ShipReportDetailVO weather = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> weatherData = new ArrayList<>();
            weather.setTitle("Weather(天气)");
            weather.setId("Weather");
            weather.setFormatType(1);
            ShipReportDetailDataVO windDirection = new ShipReportDetailDataVO();
            windDirection.setKey("windDirection");
            windDirection.setValue(shipReport.getWindDirection());
            windDirection.setType("input");
            windDirection.setDescribe("Wind - Direction");
            weatherData.add(windDirection);
            ShipReportDetailDataVO windForce = new ShipReportDetailDataVO();
            windForce.setKey("windForce");
            if (null != shipReport.getWindForce()) {
                windForce.setValue(shipReport.getWindForce().toString());
            }
            windForce.setType("input");
            windForce.setDescribe("Wind - Force (Beaufort)");
            weatherData.add(windForce);
            ShipReportDetailDataVO seaState = new ShipReportDetailDataVO();
            seaState.setKey("seaState");
            if (null != shipReport.getSeaState()) {
                seaState.setValue(shipReport.getSeaState().toString());
            }
            seaState.setType("input");
            seaState.setDescribe("Sea state");
            weatherData.add(seaState);
            ShipReportDetailDataVO seawaterTemp = new ShipReportDetailDataVO();
            seawaterTemp.setKey("seawaterTemp");
            if (null != shipReport.getSeawaterTemp()) {
                seawaterTemp.setValue(shipReport.getSeawaterTemp().toString());
            }
            seawaterTemp.setType("input");
            seawaterTemp.setUnit("°C");
            seawaterTemp.setDescribe("Seawater Temp");
            weatherData.add(seawaterTemp);
            ShipReportDetailDataVO durationWeather = new ShipReportDetailDataVO();
            durationWeather.setKey("durationWeather");
            durationWeather.setValue(shipReport.getDurationWeather());
            durationWeather.setType("input");
            durationWeather.setDescribe("Duration of weather > Beaufort 5");
            weatherData.add(durationWeather);
            ShipReportDetailDataVO distanceSteamWeather = new ShipReportDetailDataVO();
            distanceSteamWeather.setKey("distanceSteamWeather");
            if (null != shipReport.getDistanceSteamWeather()) {
                distanceSteamWeather.setValue(shipReport.getDistanceSteamWeather().toString());
            }
            distanceSteamWeather.setType("input");
            distanceSteamWeather.setUnit("N.miles");
            distanceSteamWeather.setDescribe("Distance steamed in weather > Beaufort 5");
            weatherData.add(distanceSteamWeather);
            ShipReportDetailDataVO fuelConsumeWeather = new ShipReportDetailDataVO();
            fuelConsumeWeather.setKey("fuelConsumeWeather");
            if (null != shipReport.getFuelConsumeWeather()) {
                fuelConsumeWeather.setValue(shipReport.getFuelConsumeWeather().toString());
            }
            fuelConsumeWeather.setType("input");
            fuelConsumeWeather.setUnit("tonnes");
            fuelConsumeWeather.setDescribe("Fuel consumed in weather > Beaufort 5");
            weatherData.add(fuelConsumeWeather);
            weather.setData(weatherData);

            //LNG ROB(ROB)
            ShipReportDetailVO lngRob = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> lngRobData = new ArrayList<>();
            lngRob.setTitle("LNG ROB(ROB)");
            lngRob.setId("LNG ROB");
            lngRob.setFormatType(1);
            ShipReportDetailDataVO lngRobT = new ShipReportDetailDataVO();
            lngRobT.setKey("lngRobTa");
            if (null != shipReport.getLngRobTa()) {
                lngRobT.setValue(shipReport.getLngRobTa().toString());
            }
            lngRobT.setType("input");
            lngRobT.setUnit("m³");
            lngRobT.setDescribe("Tank#1");
            lngRobData.add(lngRobT);
            ShipReportDetailDataVO lngRobTan = new ShipReportDetailDataVO();
            lngRobTan.setKey("lngRobTan");
            lngRobTan.setValue(shipReport.getLngRobTan());
            lngRobTan.setType("input");
            lngRobTan.setUnit("m³");
            lngRobTan.setDescribe("Tank#2");
            lngRobData.add(lngRobTan);
            ShipReportDetailDataVO lngRobTank = new ShipReportDetailDataVO();
            lngRobTank.setKey("lngRobTank");
            if (null != shipReport.getLngRobTank()) {
                lngRobTank.setValue(shipReport.getLngRobTank().toString());
            }
            lngRobTank.setType("input");
            lngRobTank.setUnit("m³");
            lngRobTank.setDescribe("Tank#3");
            lngRobData.add(lngRobTank);
            ShipReportDetailDataVO lngRobCtms = new ShipReportDetailDataVO();
            lngRobCtms.setKey("lngRobCtms");
            if (null != shipReport.getLngRobCtms()) {
                lngRobCtms.setValue(shipReport.getLngRobCtms().toString());
            }
            lngRobCtms.setType("input");
            lngRobCtms.setUnit("m³");
            lngRobCtms.setDescribe("Tank#4");
            lngRobData.add(lngRobCtms);
            lngRob.setData(lngRobData);

            //平均货舱温度：Average LNG temp
            ShipReportDetailVO averageLng = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> averageLngData = new ArrayList<>();
            averageLng.setTitle("Average LNG temp(平均货舱温度)");
            averageLng.setId("Average LNG temp");
            averageLng.setFormatType(1);
            ShipReportDetailDataVO averageLngTank = new ShipReportDetailDataVO();
            averageLngTank.setKey("averageLngTank");
            averageLngTank.setValue(shipReport.getAverageLngTank());
            averageLngTank.setType("input");
            averageLngTank.setUnit("Deg.C");
            averageLngTank.setDescribe("Tank#1");
            averageLngData.add(averageLngTank);
            ShipReportDetailDataVO averageLngTankDeg = new ShipReportDetailDataVO();
            averageLngTankDeg.setKey("averageLngTankDeg");
            if (null != shipReport.getAverageLngTankDeg()) {
                averageLngTankDeg.setValue(shipReport.getAverageLngTankDeg().toString());
            }
            averageLngTankDeg.setType("input");
            averageLngTankDeg.setUnit("Deg.C");
            averageLngTankDeg.setDescribe("Tank#2");
            averageLngData.add(averageLngTankDeg);
            ShipReportDetailDataVO averageLngTankDegc = new ShipReportDetailDataVO();
            averageLngTankDegc.setKey("averageLngTankDegc");
            if (null != shipReport.getAverageLngTankDegc()) {
                averageLngTankDegc.setValue(shipReport.getAverageLngTankDegc().toString());
            }
            averageLngTankDegc.setType("input");
            averageLngTankDegc.setUnit("Deg.C");
            averageLngTankDegc.setDescribe("Tank#3");
            averageLngData.add(averageLngTankDegc);
            ShipReportDetailDataVO averageLngTankDec = new ShipReportDetailDataVO();
            averageLngTankDec.setKey("averageLngTankDec");
            if (null != shipReport.getAverageLngTankDec()) {
                averageLngTankDec.setValue(shipReport.getAverageLngTankDec().toString());
            }
            averageLngTankDec.setType("input");
            averageLngTankDec.setUnit("Deg.C");
            averageLngTankDec.setDescribe("Tank#4");
            averageLngData.add(averageLngTankDec);
            averageLng.setData(averageLngData);

            //平均货舱压力：Average cargo tank pressure
            ShipReportDetailVO averageCargo = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> averageCargoData = new ArrayList<>();
            averageCargo.setTitle("Average cargo tank pressure(平均货舱压力)");
            averageCargo.setId("Average cargo tank pressure");
            averageCargo.setFormatType(1);
            ShipReportDetailDataVO averageCargoPre = new ShipReportDetailDataVO();
            averageCargoPre.setKey("averageCargoPre");
            if (null != shipReport.getAverageCargoPre()) {
                averageCargoPre.setValue(shipReport.getAverageCargoPre().toString());
            }
            averageCargoPre.setType("input");
            averageCargoPre.setUnit("kPa");
            averageCargoPre.setDescribe("Tank#1");
            averageCargoData.add(averageCargoPre);
            ShipReportDetailDataVO averageCargoPres = new ShipReportDetailDataVO();
            averageCargoPres.setKey("averageCargoPres");
            if (null != shipReport.getAverageCargoPres()) {
                averageCargoPres.setValue(shipReport.getAverageCargoPres().toString());
            }
            averageCargoPres.setType("input");
            averageCargoPres.setUnit("kPa");
            averageCargoPres.setDescribe("Tank#2");
            averageCargoData.add(averageCargoPres);
            ShipReportDetailDataVO averageCargoPress = new ShipReportDetailDataVO();
            averageCargoPress.setKey("averageCargoPress");
            if (null != shipReport.getAverageCargoPress()) {
                averageCargoPress.setValue(shipReport.getAverageCargoPress().toString());
            }
            averageCargoPress.setType("input");
            averageCargoPress.setUnit("kPa");
            averageCargoPress.setDescribe("Tank#3");
            averageCargoData.add(averageCargoPress);
            ShipReportDetailDataVO averageCargoPressure = new ShipReportDetailDataVO();
            averageCargoPressure.setKey("averageCargoPressure");
            if (null != shipReport.getAverageCargoPressure()) {
                averageCargoPressure.setValue(shipReport.getAverageCargoPressure().toString());
            }
            averageCargoPressure.setType("input");
            averageCargoPressure.setUnit("kPa");
            averageCargoPressure.setDescribe("Tank#4");
            averageCargoData.add(averageCargoPressure);
            averageCargo.setData(averageCargoData);

            //LNG消耗：LNG consumption
            ShipReportDetailVO lngConsumption = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> lngConsumptionData = new ArrayList<>();
            lngConsumption.setTitle("LNG consumption(LNG消耗)");
            lngConsumption.setId("LNG consumption");
            lngConsumption.setFormatType(1);
            ShipReportDetailDataVO lngMg = new ShipReportDetailDataVO();
            lngMg.setKey("lngMg");
            if (null != shipReport.getLngMg()) {
                lngMg.setValue(shipReport.getLngMg().toString());
            }
            lngMg.setType("input");
            lngMg.setUnit("m³");
            lngMg.setDescribe("M/G");
            lngConsumptionData.add(lngMg);
            ShipReportDetailDataVO lngDg = new ShipReportDetailDataVO();
            lngDg.setKey("lngDg");
            if (null != shipReport.getLngDg()) {
                lngDg.setValue(shipReport.getLngDg().toString());
            }
            lngDg.setType("input");
            lngDg.setUnit("m³");
            lngDg.setDescribe("D/G");
            lngConsumptionData.add(lngDg);
            ShipReportDetailDataVO lngGcu = new ShipReportDetailDataVO();
            lngGcu.setKey("lngGcu");
            if (null != shipReport.getLngGcu()) {
                lngGcu.setValue(shipReport.getLngGcu().toString());
            }
            lngGcu.setType("input");
            lngGcu.setUnit("m³");
            lngGcu.setDescribe("GCU");
            lngConsumptionData.add(lngGcu);
            lngConsumption.setData(lngConsumptionData);

            //BOG reliquefied by reliquefaction system（m3）
            ShipReportDetailVO bogSystem = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> bogSystemData = new ArrayList<>();
            bogSystem.setTitle("");
            bogSystem.setId("BOG reliquefied by reliquefaction system");
            bogSystem.setFormatType(2);
            ShipReportDetailDataVO bogReliquefie = new ShipReportDetailDataVO();
            bogReliquefie.setKey("bogReliquefie");
            if (null != shipReport.getBogReliquefie()) {
                bogReliquefie.setValue(shipReport.getBogReliquefie().toString());
            }
            bogReliquefie.setType("input");
            bogReliquefie.setUnit("m³");
            bogReliquefie.setDescribe("BOG reliquefied by reliquefaction system");
            bogSystemData.add(bogReliquefie);
            bogSystem.setData(bogSystemData);

            //Physical condition of all crew onboard
            ShipReportDetailVO physicalOnboard = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> physicalOnboardData = new ArrayList<>();
            physicalOnboard.setTitle("");
            physicalOnboard.setId("Physical condition of all crew onboard");
            physicalOnboard.setFormatType(2);
            ShipReportDetailDataVO physicalConditionCrew = new ShipReportDetailDataVO();
            physicalConditionCrew.setKey("physicalConditionCrew");
            physicalConditionCrew.setValue(shipReport.getPhysicalConditionCrew());
            physicalConditionCrew.setType("input");
            physicalConditionCrew.setDescribe("Physical condition of all crew onboard");
            physicalOnboardData.add(physicalConditionCrew);
            physicalOnboard.setData(physicalOnboardData);

            //Remarks
            ShipReportDetailVO remarks = new ShipReportDetailVO();
            List<ShipReportDetailDataVO> remarksData = new ArrayList<>();
            remarks.setTitle("");
            remarks.setId("Remarks");
            remarks.setFormatType(2);
            ShipReportDetailDataVO remark = new ShipReportDetailDataVO();
            remark.setKey("remarks");
            remark.setValue(shipReport.getRemarks());
            remark.setType("input");
            remark.setDescribe("Remarks");
            remarksData.add(remark);
            remarks.setData(remarksData);

            //基础信息：Vessel Info
            shipReportDetailVOS.add(vesselInfo);
            //时间：Time
            shipReportDetailVOS.add(time);
            //位置：Position
            shipReportDetailVOS.add(position);
            //距离和速度：Distance&Speed
            shipReportDetailVOS.add(distanceSpeed);
            //消耗油/LNG：Consumption since last report
            shipReportDetailVOS.add(consumptionLng);
            //船上还剩的油/LNG：Remaining on board
            shipReportDetailVOS.add(remainBoard);
            //Total F.O. consumption since FAOP（tonnes）(单条)
            shipReportDetailVOS.add(totalConsumpFaop);
            //发动机：Engine
            shipReportDetailVOS.add(engine);
            //油气转换：Fuel/LNG
            shipReportDetailVOS.add(fuel);
            //天气：Weather
            shipReportDetailVOS.add(weather);
            //LNG ROB(ROB)
            shipReportDetailVOS.add(lngRob);
            //平均货舱温度：Average LNG temp
            shipReportDetailVOS.add(averageLng);
            //平均货舱压力：Average cargo tank pressure
            shipReportDetailVOS.add(averageCargo);
            //LNG消耗：LNG consumption
            shipReportDetailVOS.add(lngConsumption);
            //BOG reliquefied by reliquefaction system（m3）(单条)
            shipReportDetailVOS.add(bogSystem);
            //Physical condition of all crew onboard (单条)
            shipReportDetailVOS.add(physicalOnboard);
            //Remarks
            shipReportDetailVOS.add(remarks);
        }
        return shipReportDetailVOS;
    }

    @Resource
    @Lazy
    ProcessInstanceService processInstanceService;
    /**
     * 删除午报
     *
     * @param id
     * @return
     */
    @Override
    public SmShipReport removeShipReport(Long id,SpFobFileRecordService spFobFileRecordService) {
        SmShipReport shipReport = this.getById(id);
        if (null != shipReport) {

            if(shipReport.getDelApply()==1){
                throw new BusException("当前记录已提交删除申请，请勿重复提交", BaseResultCode.GENERAL_ERROR);
            }
            shipReport.setDelApply(1);
            //开启审批流程
            Map<String,Object> map = new HashMap<>();
            map.put("serviceType",1);
            map.put("module","shipReport");
            map.put("moduleName","船舶报文");
            String processInstanceId = processInstanceService.createProcessInstance2(BpmInstanceService.SYSTEM_DELETE_BPM_KEY,map,id+"");
            shipReport.setProcessInstanceId(processInstanceId);
            this.updateById(shipReport);

        }
        return shipReport;
    }

    /**
     * 新增船舶午报
     *
     * @param fileRecords
     */
    @Override
    public JsonResult saveShipReport(List<SpFobFileRecord> fileRecords) throws ParseException {
        URI httpUrl = null;
        InputStream inputStream = null;
        List<SmShipReport> saveReportList = new ArrayList<>();
        for (SpFobFileRecord fobFileRecord : fileRecords) {
            try {
                String encodedFilePath = fobFileRecord.getHttpPath().replace(" ", "%20");
                httpUrl = new URI(encodedFilePath);
                URL uri = httpUrl.toURL();
                inputStream = uri.openConnection().getInputStream();
            } catch (Exception e) {
                e.printStackTrace();
                throw new ServiceException("数据解析异常", BaseResultCode.GENERAL_ERROR.getCode());
            }
            List<SmShipReport> columnDataList = new LinkedList<>();
            ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(inputStream);
            // 选择要读取的Sheet，并忽略第一行（头部）
            ExcelReaderSheetBuilder sheetBuilder = excelReaderBuilder.sheet().headRowNumber(1);
            // 读取整个Sheet的数据
            List<Map<Integer, Object>> allRows = sheetBuilder.doReadSync();
            String shipName = allRows.get(0).get(1).toString();
            if (StringUtils.isBlank(shipName)) {
                throw new ServiceException("船舶名称不能为空", BaseResultCode.GENERAL_ERROR.getCode());
            }
            // 从allRows中按列提取数据
            for (int columnIndex = 2; columnIndex < allRows.get(0).size(); columnIndex++) {
                SmShipReport innerData = new SmShipReport();
                for (Map<Integer, Object> row : allRows) {
                    Object firstColumnValue = row.get(0);
                    // 忽略第0列和第1列为空的行
                    if (firstColumnValue != null && !firstColumnValue.toString().isEmpty() &&
                            columnIndex < row.size()) {
                        String columnValue = row.get(columnIndex) != null ? row.get(columnIndex).toString() : "";
                        if ("Vessel name".equals(firstColumnValue) && null == innerData.getVesselName()) {
                            innerData.setVesselName(shipName);
                            continue;
                        }
                        if ("Voyage number".equals(firstColumnValue) && null == innerData.getVoyageNumber()) {
                            innerData.setVoyageNumber(columnValue);
                            continue;
                        }
                        if ("Date".equals(firstColumnValue) && null == innerData.getShipReportDate()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("(0[1-9]|[1-2][0-9]|3[0-1])/(0[1-9]|1[0-2])/([0-9]{4})")) {
                                    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                                    innerData.setShipReportDate(sdf.parse(columnValue));
                                    continue;
                                } else {
                                    throw new ServiceException(shipName+"Date字段时间格式错误。请检查后重试！", BaseResultCode.GENERAL_ERROR.getCode());
                                }

                            } else {
                                throw new ServiceException(shipName+"Date字段时间不能为空！", BaseResultCode.GENERAL_ERROR.getCode());
                            }
                        }
                        if ("LT".equals(firstColumnValue) && null == innerData.getShipReportLt()) {
                            innerData.setShipReportLt(columnValue);
                            continue;
                        }
                        if ("UTC".equals(firstColumnValue) && null == innerData.getShipReportUtc()) {
                            innerData.setShipReportUtc(columnValue);
                            continue;
                        }
                        if ("Position LAT.".equals(firstColumnValue) && null == innerData.getPositionLat()) {
                            innerData.setPositionLat(columnValue);
                            continue;
                        }
                        if ("Position LONG.".equals(firstColumnValue) && null == innerData.getPositionLong()) {
                            innerData.setPositionLong(columnValue);
                            continue;
                        }
                        if ("Observed distance since last report".equals(firstColumnValue) && null == innerData.getLastReportMiles()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setLastReportMiles(integerValue);
                                    continue;
                                }
                            }

                        }
                        if ("Steaming Time since last report".equals(firstColumnValue) && null == innerData.getSteamingTime()) {
                            innerData.setSteamingTime(columnValue);
                            continue;
                        }
                        if ("Total distance since FAOP".equals(firstColumnValue) && null == innerData.getFaopMiles()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setFaopMiles(integerValue);
                                }
                                continue;
                            }

                        }
                        if ("Distance to go - To Next Port".equals(firstColumnValue) && null == innerData.getNextPortMiles()) {
                            innerData.setNextPortMiles(columnValue);
                            continue;
                        }
                        if ("Distance to go - To Final destination".equals(firstColumnValue.toString().trim()) && StringUtil.isEmpty(innerData.getFinalDestinationMiles())) {
                            innerData.setFinalDestinationMiles(columnValue);
                            continue;
                        }
                        if ("Average speed since last report".equals(firstColumnValue) && null == innerData.getLastReportKnots()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setLastReportKnots(new BigDecimal(columnValue));
                                    continue;
                                }
                            }

                        }
                        if ("Speed required to make scheduled ETA".equals(firstColumnValue.toString().trim()) && null == innerData.getScheduledEtaKnots()) {
                            innerData.setScheduledEtaKnots(columnValue);
                            continue;
                        }
                        if ("Engine RPM since last noon report".equals(firstColumnValue) && null == innerData.getEngineRpm()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setEngineRpm(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("Engine power".equals(firstColumnValue) && null == innerData.getEnginePowerKw()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setEnginePowerKw(integerValue);
                                    continue;
                                }
                            }

                        }
                        if ("Engine torque".equals(firstColumnValue) && null == innerData.getEngineTorqueKn()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setEngineTorqueKn(integerValue);
                                }
                                continue;
                            }

                        }
                        if ("Pct. Slip".equals(firstColumnValue) && null == innerData.getPctSlip()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setPctSlip(new BigDecimal(columnValue));
                                    continue;
                                }
                            }

                        }
                        if ("Consumption since last report - F.O.".equals(firstColumnValue) && null == innerData.getConsumptionFo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setConsumptionFo(integerValue);
                                    continue;
                                }
                            }

                        }
                        if ("-L. S. F. O.".equals(firstColumnValue) && null == innerData.getConsumptionLsfo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setConsumptionLsfo(columnValue);
                                    continue;
                                }
                            }

                        }
                        if ("L.S.M.D.O".equals(firstColumnValue) && null == innerData.getConsumptionLsmdo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setConsumptionLsmdo(columnValue);
                                    continue;
                                }
                            }

                        }
                        if ("- G.O.".equals(firstColumnValue) && null == innerData.getConsumptionGo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setConsumptionGo(integerValue);
                                    continue;
                                }
                            }

                        }
                        if ("-L.S.G.O.".equals(firstColumnValue) && null == innerData.getConsumptionLsgo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setConsumptionLsgo(new BigDecimal(columnValue));
                                    continue;
                                }
                            }

                        }
                        if ("Remaining on board - F.O.".equals(firstColumnValue) && null == innerData.getRemainingFo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setRemainingFo(integerValue);
                                    continue;
                                }
                            }

                        }
                        if ("-L. S. F. O.".equals(firstColumnValue) && null == innerData.getRemainingLsfo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setRemainingLsfo(columnValue);
                                    continue;
                                }
                            }

                        }
                        if ("L.S.M.D.O.".equals(firstColumnValue) && null == innerData.getRemainingLsmdo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setRemainingLsmdo(columnValue);
                                    continue;
                                }
                            }

                        }
                        if ("- G.O.".equals(firstColumnValue) && null == innerData.getRemainingGo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setRemainingGo(integerValue);
                                    continue;
                                }
                            }
                        }
                        if ("-L.S.G.O.".equals(firstColumnValue) && null == innerData.getRemainingLsgo()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setRemainingLsgo(new BigDecimal(columnValue));
                                    continue;
                                }
                            }

                        }
                        if ("-LNG".equals(firstColumnValue) && null == innerData.getRemainingLng()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setRemainingLng(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("LNG consumption since last report (by flowmeter)".equals(firstColumnValue) && null == innerData.getConsumptionFlowmeter()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setConsumptionFlowmeter(new BigDecimal(columnValue));
                                    continue;
                                }
                            }

                        }
                        if ("LNG consumption for".equals(firstColumnValue.toString().trim()) && null == innerData.getLngConsumptionFor()) {
                            innerData.setLngConsumptionFor(columnValue);
                            continue;
                        }
                        if ("Fuel oil equivalent factor".equals(firstColumnValue) && null == innerData.getFuelOilFactor()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setFuelOilFactor(new BigDecimal(columnValue));
                                    continue;
                                }
                            }

                        }
                        if ("LNG fuel equivalent".equals(firstColumnValue) && null == innerData.getLngFuelEquivalent()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setLngFuelEquivalent(new BigDecimal(columnValue));
                                    continue;
                                }
                            }

                        }
                        if ("Total F.O. consumption since FAOP".equals(firstColumnValue) && null == innerData.getTotalFoFaop()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setTotalFoFaop(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("Wind - Direction".equals(firstColumnValue) && null == innerData.getWindDirection()) {
                            innerData.setWindDirection(columnValue);
                            continue;
                        }
                        if ("Wind - Force (Beaufort)".equals(firstColumnValue) && null == innerData.getWindForce()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setWindForce(integerValue);
                                    continue;
                                }
                            }
                        }
                        if ("Sea state".equals(firstColumnValue) && null == innerData.getSeaState()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setSeaState(integerValue);
                                    continue;
                                }
                            }
                        }
                        if ("Seawater Temp (°C)".equals(firstColumnValue) && null == innerData.getSeawaterTemp()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    Double doubleValue = Double.parseDouble(columnValue);
                                    Integer integerValue = doubleValue.intValue();
                                    innerData.setSeawaterTemp(integerValue);
                                    continue;
                                }
                            }
                        }
                        if ("Duration of weather > Beaufort 5".equals(firstColumnValue) && null == innerData.getDurationWeather()) {
                            innerData.setDurationWeather(columnValue);
                            continue;
                        }
                        if ("Distance steamed in weather > Beaufort 5".equals(firstColumnValue) && null == innerData.getDistanceSteamWeather()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setDistanceSteamWeather(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("Fuel consumed in weather > Beaufort 5".equals(firstColumnValue) && null == innerData.getFuelConsumeWeather()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setFuelConsumeWeather(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("Average LNG temp.- Tank # 1".equals(firstColumnValue.toString().trim()) && null == innerData.getAverageLngTank()) {
                            innerData.setAverageLngTank(columnValue);
                            continue;
                        }
                        if ("- Tank # 2".equals(firstColumnValue.toString().trim()) && null == innerData.getAverageLngTankDeg()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setAverageLngTankDeg(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("-Tank # 3".equals(firstColumnValue.toString().trim()) && null == innerData.getAverageLngTankDegc()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setAverageLngTankDegc(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("-Tank # 4".equals(firstColumnValue.toString().trim()) && null == innerData.getAverageLngTankDec()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setAverageLngTankDec(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("Average cargo tank pressure - Tank # 1".equals(firstColumnValue.toString().trim()) && null == innerData.getAverageCargoPre()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setAverageCargoPre(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("- Tank # 2".equals(firstColumnValue.toString().trim()) && null == innerData.getAverageCargoPres()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setAverageCargoPres(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("- Tank # 3".equals(firstColumnValue.toString().trim()) && null == innerData.getAverageCargoPress()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setAverageCargoPress(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("- Tank # 4".equals(firstColumnValue.toString().trim()) && null == innerData.getAverageCargoPressure()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setAverageCargoPressure(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("LNG ROB - Tank # 1(BY CTMS DATA)".equals(firstColumnValue.toString().trim()) && null == innerData.getLngRobTa()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setLngRobTa(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("-Tank # 2 (BY CTMS DATA)".equals(firstColumnValue.toString().trim()) && null == innerData.getLngRobTan()) {
                            innerData.setLngRobTan(columnValue);
                            continue;
                        }
                        if ("-Tank # 3 (BY CTMS DATA)".equals(firstColumnValue.toString().trim()) && null == innerData.getLngRobTank()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setLngRobTank(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("-Tank # 4 (BY CTMS DATA)".equals(firstColumnValue.toString().trim()) && null == innerData.getLngRobCtms()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setLngRobCtms(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("ETA NEXT PORT - Date/Time(LT)".equals(firstColumnValue) && null == innerData.getEtaNextPort()) {
                            innerData.setEtaNextPort(columnValue);
                            continue;
                        }
                        if ("Deviations".equals(firstColumnValue) && null == innerData.getDeviations()) {
                            innerData.setDeviations(columnValue);
                            continue;
                        }
                        if ("Physical condition of all crew onboard".equals(firstColumnValue) && null == innerData.getPhysicalConditionCrew()) {
                            innerData.setPhysicalConditionCrew(columnValue);
                            continue;
                        }
                        if ("LNG consumption for M/G".equals(firstColumnValue) && null == innerData.getLngMg()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setLngMg(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("LNG consumption for D/G".equals(firstColumnValue) && null == innerData.getLngDg()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setLngDg(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("LNG consumption for GCU".equals(firstColumnValue) && null == innerData.getLngGcu()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setLngGcu(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("BOG reliquefied  by reliquefaction system".equals(firstColumnValue) && null == innerData.getBogReliquefie()) {
                            if (StringUtils.isNotBlank(columnValue)) {
                                if (columnValue.matches("^-?[0-9]+(\\.[0-9]+)?$")) {
                                    innerData.setBogReliquefie(new BigDecimal(columnValue));
                                    continue;
                                }
                            }
                        }
                        if ("Remarks :".equals(firstColumnValue) && null == innerData.getRemarks()) {
                            innerData.setRemarks(columnValue);
                        }
                    }
                }
                if (StringUtils.isBlank(innerData.getVesselName()) || innerData.getShipReportDate() == null) {
                    throw new ServiceException("船只【"+innerData.getVesselName()+"】的Vessel name/Date字段信息残缺，请核验！", BaseResultCode.GENERAL_ERROR.getCode());
                }
                columnDataList.add(innerData);
            }
            if (CollectionUtil.isNotEmpty(columnDataList)) {
                List<SmShipReport> list = columnDataList.stream().filter(d -> StringUtils.isNotBlank(d.getVesselName())).collect(Collectors.toList());
                list.forEach(d -> {
                    List<SmShipReport> shipReports = this.getBaseMapper().selectList(new LambdaQueryWrapper<SmShipReport>()
                            .eq(SmShipReport::getVesselName, d.getVesselName())
                            .eq(SmShipReport::getShipReportDate, d.getShipReportDate())
                    );
                    //数据库中已存在的，不新增
                    if (CollectionUtil.isEmpty(shipReports)) {
                        SpInformation information = informationService.queryShipImoByShipName(d.getVesselName().toUpperCase());
                        if (null != information) {
                            d.setImo(information.getImo());
                        }
                        d.setFileRecordId(fobFileRecord.getId());
                        d.setCreateBy(SecurityUtils.getUsername());
                        d.setCreateDate(new Date());
                        d.setUpdateDate(d.getCreateDate());
                        d.setId(IDUtil.nextId());
                        d.setDelApply(0);
                        saveReportList.add(d);
                    }
                });
            }
            //新增船舶午报动态
            SmShipReportRecord shipReportRecord = new SmShipReportRecord();
            shipReportRecord.setShipReportId(fobFileRecord.getId());
            shipReportRecord.setOperateType(1);
            shipReportRecord.setOperateRemark("新增船舶午报:" + fobFileRecord.getName());
            shipReportRecord.setOperateTime(new Date());
            shipReportRecord.setOperateBy(SecurityUtils.getUsername());
            shipReportRecordService.save(shipReportRecord);
        }

        if (CollectionUtil.isNotEmpty(saveReportList)){
            saveReportList.forEach(item -> {
                int insert = baseMapper.insert(item);
                //新增成功以后同步到燃油台账
                if (insert == 1) {
                    TzFuelRecord fuelRecord = new TzFuelRecord();
                    fuelRecord.setShipName(item.getVesselName());
                    fuelRecord.setImo(item.getImo());
                    if (null != item.getShipReportDate()) {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        fuelRecord.setMessageDate(sdf.format(item.getShipReportDate()));
                    }
                    //VLSFO 日剩余量
                    BigDecimal remainingLsfo = BigDecimal.ZERO;
                    if (null != item.getRemainingLsfo()) {
                        remainingLsfo = new BigDecimal(item.getRemainingLsfo());
                    }
                    fuelRecord.setVlsfoDayLeave(remainingLsfo);
                    //VLSFO 日消耗量
                    BigDecimal consumptionLsfo = BigDecimal.ZERO;
                    if (null != item.getConsumptionLsfo()) {
                        consumptionLsfo = new BigDecimal(item.getConsumptionLsfo());
                    }
                    fuelRecord.setVlsfoDayUse(consumptionLsfo);
                    //LSMGO日 剩余量
                    BigDecimal remainingLsmdo = BigDecimal.ZERO;
                    if (null != item.getRemainingLsmdo()) {
                        remainingLsmdo = new BigDecimal(item.getRemainingLsmdo());
                    }
                    fuelRecord.setLsmgoDayLeave(remainingLsmdo);
                    //LSMGO日消耗量
                    BigDecimal consumptionLsmdo = BigDecimal.ZERO;
                    if (null != item.getConsumptionLsmdo()) {
                        consumptionLsmdo = new BigDecimal(item.getConsumptionLsmdo());
                    }
                    fuelRecord.setLsmgoDayUse(consumptionLsmdo);
                    tzFuelRecordService.dataTransfer(fuelRecord);
                }else {
                    throw new ServiceException("保存失败！", BaseResultCode.GENERAL_ERROR.getCode());
                }
            });
        }
        return JsonResult.success();
    }

    /**
     * 查询船舶午报动态
     *
     * @param id
     * @return
     */
    @Override
    public List<SmShipReportRecord> getShipReportRecord(Long id) {
        List<SmShipReportRecord> reportRecords = new ArrayList<>();
        SmShipReport shipReport = this.getById(id);
        if (null != shipReport) {
            reportRecords = shipReportRecordService.list(new LambdaQueryWrapper<SmShipReportRecord>()
                    .eq(SmShipReportRecord::getShipReportId, shipReport.getFileRecordId())
                    .orderByDesc(SmShipReportRecord::getOperateTime)
            );
        }
        return reportRecords;
    }

    @Resource
    @Lazy
    SpFobFileRecordService spFobFileRecordService;
    @Override
    public void cancelDelete(String businessKey, Integer staus) {
        SmShipReport  shipReport = this.getById(businessKey);
        if(staus==1){
             this.removeById(businessKey);
            //新增船舶午报动态
            SpFobFileRecord fileRecord = spFobFileRecordService.getById(shipReport.getFileRecordId());
            SmShipReportRecord shipReportRecord = new SmShipReportRecord();
            shipReportRecord.setShipReportId(shipReport.getFileRecordId());
            shipReportRecord.setOperateType(3);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
            shipReportRecord.setOperateRemark("删除船舶午报:" + fileRecord.getName() + ",其中数据：" + shipReport.getVesselName() + sdf.format(shipReport.getShipReportDate()));
            shipReportRecord.setOperateTime(new Date());
            shipReportRecord.setOperateBy(SecurityUtils.getUsername());
            shipReportRecordService.save(shipReportRecord);
        }else if(staus==2){
            shipReport.setDelApply(2);
            this.updateById(shipReport);
        }else {
            shipReport.setDelApply(0);
            this.updateById(shipReport);
        }

    }

    @Override
    public PageInfo<SmShipReport> queryShipPage(SmShipReport shipReport) {
        PageHelper.startPage(shipReport.getPageNum(),shipReport.getPageSize());
        List<SmShipReport> shipReportList = baseMapper.queryShipPage(shipReport);
        PageInfo<SmShipReport> pageInfo = new PageInfo<>(shipReportList);
        return pageInfo;
    }

    @Override
    public List<SmShipReport> exportShipReport(SmShipReport shipReport) {
        return baseMapper.queryShipPage(shipReport);
    }

    @Override
    public List<QueryFuelConsumptionTrendInfo> queryFuelConsumptionTrend(String shipName, String startDate, String endDate) {
        List<QueryFuelConsumptionTrendInfo> returnList = new ArrayList<>();
        List<SmShipReport> reportList = baseMapper.queryReportList(shipName,startDate,endDate);
        if (CollectionUtil.isNotEmpty(reportList)){
            Map<Date, List<SmShipReport>> map = reportList.stream().collect(Collectors.groupingBy(SmShipReport::getShipReportDate));
            map.forEach((key,value) -> {
                QueryFuelConsumptionTrendInfo queryFuelConsumptionTrendInfo = new QueryFuelConsumptionTrendInfo();
                String date = DateUtil.format(key, DatePattern.NORM_DATE_FORMATTER);
                queryFuelConsumptionTrendInfo.setShipReportDate(date);
                BigDecimal reportFOTotal = new BigDecimal(0);
                BigDecimal reportLSFOTotal = new BigDecimal(0);
                BigDecimal reportLSMDOTotal = new BigDecimal(0);
                BigDecimal reportGOTotal = new BigDecimal(0);
                BigDecimal reportLSGOTotal = new BigDecimal(0);
                for (SmShipReport smShipReport : value) {
                    if (null != smShipReport.getConsumptionFo()) {
                        reportFOTotal = reportFOTotal.add(new BigDecimal(smShipReport.getConsumptionFo()));
                    }
                    if (null != smShipReport.getConsumptionLsfo()) {
                        reportLSFOTotal = reportLSFOTotal.add(new BigDecimal(smShipReport.getConsumptionLsfo()));
                    }
                    if (null != smShipReport.getConsumptionLsmdo()) {
                        reportLSMDOTotal = reportLSMDOTotal.add(new BigDecimal(smShipReport.getConsumptionLsmdo()));
                    }
                    if (null != smShipReport.getConsumptionGo()) {
                        reportGOTotal = reportGOTotal.add(new BigDecimal(smShipReport.getConsumptionGo()));
                    }
                    if (null != smShipReport.getConsumptionLsgo()) {
                        reportLSGOTotal = reportLSGOTotal.add(smShipReport.getConsumptionLsgo());
                    }
                }
                QueryReportInfo queryReportInfo1 = new QueryReportInfo();
                queryReportInfo1.setShipReportDate(date);
                queryReportInfo1.setName("F.O");
                queryReportInfo1.setNumber(reportFOTotal);
                queryReportInfo1.setUnit("tonnes");
                queryFuelConsumptionTrendInfo.setReportFO(queryReportInfo1);
                QueryReportInfo queryReportInfo2 = new QueryReportInfo();
                queryReportInfo2.setShipReportDate(date);
                queryReportInfo2.setName("L.S.F.O");
                queryReportInfo2.setNumber(reportLSFOTotal);
                queryReportInfo2.setUnit("tonnes");
                queryFuelConsumptionTrendInfo.setReportFSFO(queryReportInfo2);
                QueryReportInfo queryReportInfo3 = new QueryReportInfo();
                queryReportInfo3.setShipReportDate(date);
                queryReportInfo3.setName("L.S.M.D.O");
                queryReportInfo3.setNumber(reportLSMDOTotal);
                queryReportInfo3.setUnit("tonnes");
                queryFuelConsumptionTrendInfo.setReportFSMDO(queryReportInfo3);
                QueryReportInfo queryReportInfo4 = new QueryReportInfo();
                queryReportInfo4.setShipReportDate(date);
                queryReportInfo4.setName("G.O");
                queryReportInfo4.setNumber(reportGOTotal);
                queryReportInfo4.setUnit("tonnes");
                queryFuelConsumptionTrendInfo.setReportGO(queryReportInfo4);
                QueryReportInfo queryReportInfo5 = new QueryReportInfo();
                queryReportInfo5.setShipReportDate(date);
                queryReportInfo5.setName("L.S.G.O");
                queryReportInfo5.setNumber(reportLSGOTotal);
                queryReportInfo5.setUnit("tonnes");
                queryFuelConsumptionTrendInfo.setReportLSGO(queryReportInfo5);
                returnList.add(queryFuelConsumptionTrendInfo);
            });
        }
        if (CollectionUtil.isNotEmpty(returnList)){
            return returnList.stream().sorted(Comparator.comparing(QueryFuelConsumptionTrendInfo::getShipReportDate)).collect(Collectors.toList());
        }
        return null;
    }

    @Override
    public List<QueryEvaporationConsumptionTrendInfo> queryEvaporationConsumptionTrend(String shipName, String startDate, String endDate) {
        List<QueryEvaporationConsumptionTrendInfo> returnList = new ArrayList<>();
        List<SmShipReport> reportList = baseMapper.queryReportList(shipName,startDate,endDate);
        if (CollectionUtil.isNotEmpty(reportList)){
            Map<Date, List<SmShipReport>> map = reportList.stream().collect(Collectors.groupingBy(SmShipReport::getShipReportDate));
            map.forEach((key,value) -> {
                QueryEvaporationConsumptionTrendInfo info = new QueryEvaporationConsumptionTrendInfo();
                String date = DateUtil.format(key, DatePattern.NORM_DATE_FORMATTER);
                info.setShipReportDate(date);
                BigDecimal consumptionMGTotal = new BigDecimal(0);
                BigDecimal consumptionDGTotal = new BigDecimal(0);
                BigDecimal consumptionGCUTotal = new BigDecimal(0);
                for (SmShipReport smShipReport : value) {
                    if (null != smShipReport.getLngMg()) {
                        consumptionMGTotal = consumptionMGTotal.add(smShipReport.getLngMg());
                    }
                    if (null != smShipReport.getLngDg()) {
                        consumptionDGTotal = consumptionDGTotal.add(smShipReport.getLngDg());
                    }
                    if (null != smShipReport.getLngGcu()) {
                        consumptionGCUTotal = consumptionGCUTotal.add(smShipReport.getLngGcu());
                    }
                }
                QueryReportInfo queryReportInfo1 = new QueryReportInfo();
                queryReportInfo1.setShipReportDate(date);
                queryReportInfo1.setName("M/G");
                queryReportInfo1.setNumber(consumptionMGTotal);
                queryReportInfo1.setUnit("m³");
                info.setConsumptionMG(queryReportInfo1);
                QueryReportInfo queryReportInfo2 = new QueryReportInfo();
                queryReportInfo2.setShipReportDate(date);
                queryReportInfo2.setName("D/G");
                queryReportInfo2.setNumber(consumptionDGTotal);
                queryReportInfo2.setUnit("m³");
                info.setConsumptionDG(queryReportInfo2);
                QueryReportInfo queryReportInfo3 = new QueryReportInfo();
                queryReportInfo3.setShipReportDate(date);
                queryReportInfo3.setName("GCU");
                queryReportInfo3.setNumber(consumptionGCUTotal);
                queryReportInfo3.setUnit("m³");
                info.setConsumptionGCU(queryReportInfo3);
                returnList.add(info);
            });
        }
        if (CollectionUtil.isNotEmpty(returnList)){
            return returnList.stream().sorted(Comparator.comparing(QueryEvaporationConsumptionTrendInfo::getShipReportDate)).collect(Collectors.toList());
        }
        return null;
    }

    @Override
    public PageInfo<SmShipReport> queryShipReportList(SmShipReport shipReport) {
        PageHelper.startPage(shipReport.getPageNum(),shipReport.getPageSize());
        List<SmShipReport> list = baseMapper.queryShipReportList(shipReport);
        PageInfo<SmShipReport> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
